#!/bin/bash

# PARAMETERS:
# $1 -> Video file for to split
# $2 -> Times size of split

if [ $# != 2 ]; then
  echo ""
  echo "ERROR: number of parameters incorrect"
  exit 1
fi


sizeTime=599 # in seconds
sizeTimeFile=$2  # in seconds

timeStart=0 # in seconds
timeEnd=$sizeTime # in seconds

count=0


mkdir  folder
cp -f $1 ./folder/temp.avi

cd folder

while [ $timeStart -lt $sizeTimeFile ]; do
  echo "-------------------------------------------------------------------"
  mencoder -endpos $sizeTime -ovc copy -oac copy temp.avi -o $count$1 #> /dev/null
  mencoder -ss $sizeTime -ovc copy -oac copy temp.avi -o temp2.avi #> /dev/null
  echo   $count$1 : $timeStart - $timeEnd 
  
  echo "dale ENTER"
   read file
  mv -f temp2.avi temp.avi
  
  let timeStart=$timeEnd
  let timeEnd=$timeEnd+$sizeTime
  if [ $timeEnd -gt $sizeTimeFile ]; then
    let timeEnd=$sizeTimeFile
  fi
  let count=$count+1
  
done
echo  "FIN"
cd ..

# mencoder -ss $timeStart  -endpos $timeEnd -ovc copy -oac copy $1 -o $count$1
